package lx1129;

import java.sql.*;
import java.util.HashMap;
import java.util.Map;

import util.DBUtil;

public class Test4 {
	public static void main(String[] args){
		Map<String,Object> map=getUserMap(12);
		map.forEach((k,v)->System.out.println(k+":"+v));
	}
	static Map<String,Object> getUserMap(int id){
	    Map<String,Object> map=new HashMap<>();
	    Connection conn=null;
	    PreparedStatement stm=null;
	    ResultSet rs=null;
	    try {
			conn=DBUtil.getconn();
			String sql="select * from userinfo where id="+id;
			stm=conn.prepareStatement(sql);
			rs=stm.executeQuery();
			while(rs.next()){
				ResultSetMetaData rm=rs.getMetaData();
				int len=rm.getColumnCount();
				for(int i=1;i<=len;i++){
					String k=rm.getColumnName(i);
					Object v=rs.getObject(k);
					map.put(k, v);
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally{
			DBUtil.close(rs, stm, conn);
		}
	    return map;
	}

}
